<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="div">
        <input type="checkbox" name="hobby" value="唱">唱
        <input type="checkbox" name="hobby" value="跳">跳
        <input type="checkbox" name="hobby" value="RAP">RAP
        <input type="checkbox" name="hobby" value="篮球">篮球
    </div>

    <p></p>
    <script>
        var div = document.querySelector("div");
        var input = document.querySelectorAll("input");
        var p = document.querySelector("p");

        div.onchange = function () {
            var arr = []
            for (let i = 0; i < input.length; i++) {
                if (input[i].checked) {
                    arr.push(input[i].value);
                }
            }
            for(var value of arr){
                
                p.innerText = "你的爱好="+arr;
              
            }  
        
        }
    



    </script>
</body>

</html>